package com.sky.mapper;

import cn.mybatis.mp.core.mybatis.mapper.MybatisMapper;
import com.sky.entity.Books;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;

/**
* @author 31827
* @description 针对表【books(图书表)】的数据库操作Mapper
* @createDate 2024-11-23 16:50:03
* @Entity com.sky.entity.Books
*/
@Mapper
public interface BooksMapper extends MybatisMapper<Books> {

    @Select("<script>" +
            "SELECT * FROM books WHERE book_id IN " +
            "<foreach item='item' index='index' collection='list' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<Books> selectBatchIds(List<Integer> ids);

    /**
     * 查询热门图书列表（根据热度分数）
     * @return 热门图书列表
     */
    @Select("SELECT book_id as bookId, title as bookName, " +
            "CAST(popularity_score AS SIGNED) as borrowCount " +
            "FROM books " +
            "ORDER BY popularity_score DESC " +
            "LIMIT 5")
    List<Map<String, Object>> selectPopularBooks();

}
